home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Goodies / ColorPicker 2.0a6 / ColorPicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  13.0 KB  |  481 lines  |  [TEXT/KAHL]

  1. /*
  2. *
  3. *
  4. *        The public Color Picker Manager routines and data structures.
  5. *
  6. *        Created by: Shannon Holland
  7. *        Copyright:    © 1991-1992 by Apple Computer, Inc., all rights reserved.
  8. *
  9. *    History:
  10. *        10-13-91    SAH        Created this file.
  11. *
  12. */
  13.  
  14. #include <QuickDraw.h>
  15. #include <Events.h>
  16. #include <Balloons.h>
  17.  
  18. #ifndef ColorPicker
  19. #define    ColorPicker
  20.  
  21. #define        kDefaultWidth    383
  22. #define        kDefaultHeight    238
  23.  
  24.     /* Data structures and flags */
  25.  
  26. #ifndef __CMAPPLICATION__
  27. typedef struct CMPRofile **CMProfileHandle;
  28.  
  29. typedef struct {
  30.     unsigned short        X;            /* these should be 1.15 fixed numbers */
  31.     unsigned short        Y;
  32.     unsigned short        Z;
  33. } XYZColor;
  34.  
  35. typedef struct {
  36.     unsigned short        c;            /* these should be 1.15 fixed numbers */
  37.     unsigned short        m;
  38.     unsigned short        y;
  39.     unsigned short        k;
  40. } CMYKColor;
  41.  
  42. typedef union {
  43.     RGBColor        rgb;
  44.     XYZColor        xyz;
  45.     CMYKColor    cmyk;
  46.     unsigned short    reserved[4];
  47. } CMColor, *CMColorList;
  48.  
  49. #endif
  50.  
  51. typedef struct PMColor
  52. {
  53.     CMProfileHandle profile;
  54.     CMColor color;
  55. } PMColor,*PMColorPtr;
  56.  
  57. typedef struct PrivatePickerRecord **picker;
  58.  
  59. /*
  60. *    The actions returned to the application from DoPickerEvent
  61. */
  62. enum PickerAction
  63. {
  64.     kDidNothing,
  65.     kColorChanged,
  66.     kOkHit,
  67.     kCancelHit,
  68.     kNewPickerChosen,
  69.     kApplItemHit
  70. };
  71.  
  72. typedef short PickerAction;
  73.  
  74. /*
  75. *    The types of colors a picker must maintain
  76. */
  77. enum ColorTypes
  78. {
  79.     kOriginalColor,        // the original color passed to the picker manager
  80.     kNewColor            // the current color the user has chosen
  81. };
  82.  
  83. typedef short ColorType;
  84.  
  85. /*
  86. *    The types of edit operations that are sent with the kEdit message
  87. */
  88. enum EditOperations
  89. {
  90.     kCut,
  91.     kCopy,
  92.     kPaste,
  93.     kClear,
  94.     kUndo
  95. };
  96.  
  97. typedef short EditOperation;
  98.  
  99. /*
  100. *    The Item hit modifiers. These are sent along with the itemHit message and inform the picker
  101. *    of what it was that caused the item hit.
  102. */
  103. enum ItemHitModiefiers
  104. {
  105.     kMouseDown,            // mouseDown on item
  106.     kKeyDown,            // keydown in current edit item
  107.     kFieldEntered,        // tab into an edit field
  108.     kFieldLeft,            // tab out of an edit field
  109.     kCutOp,                // cut in current edit field
  110.     kCopyOp,            // copy in current edit field
  111.     kPasteOp,            // paste in current edit field
  112.     kClearOp,            // clear in current edit field
  113.     kUndoOp                // undo in current edit field
  114. };
  115.  
  116. typedef short ItemModifier;
  117.  
  118.  
  119. /*
  120. *    The dialog placement specifiers. These tell the picker manager where to place
  121. *    the picker dialog (used for system dialogs).
  122. */
  123.  
  124. enum DialogPlacementSpecifiers
  125. {
  126.     kAtSpecifiedOrigin,
  127.     kDeepestColorScreen,
  128.     kCenterOnMainScreen
  129. };
  130.  
  131. typedef short DialogPlacementSpec;
  132.  
  133.  
  134. /*
  135. *    Picker flags
  136. */
  137.  
  138. // these flags may be set by the app and are passed through to the picker
  139. #define        DialogIsMoveable        1        // the dialog can be moved
  140. #define        DialogIsModal            2        // the dialog is modal
  141. #define        CanModifyPalette        4        // the picker is allowed to install a palette
  142. #define        CanAnimatePalette        8        // the picker is allowed to animate the palette
  143. #define        AppIsColorSyncAware        16        // The application is ColorSync aware and can therfore
  144.                                             // convert colors between spaces (ie it can accept non-RGB
  145.                                             // colors)
  146.  
  147. // these flags are set by the picker manager (overriding any application settings)
  148. #define        InSystemDialog            32        // the picker is in a system dialog
  149. #define        InApplicationDialog        64        // the picker is in an application dialog
  150. #define        InPickerDialog            128        // the picker is in its own dialog
  151. #define        DetachedFromChoices        256        // the picker has been detached from the choices
  152.                                             // list
  153.  
  154.  
  155. /*
  156. *    Picker attributes (bits 23 to 0 in the componentFlags field of the component thng)
  157. */
  158.  
  159. #define        CanDoColor                1        // the picker can live in Color QD Environments
  160. #define        CanDoBlackWhite            2        // the picker can live in Classic QD Environments
  161. #define        AlwaysModifiesPalette    4        // the picker will modify palette entries on indexed
  162.                                             // devices
  163. #define        MayModifyPalette        8        // the picker will modify palette if told it can
  164. #define        PickerIsColorSyncAware    16        // the picker is ColorSync aware and can accept 
  165.                                             // non-RGB colors
  166. #define        CanDoSystemDialog        32        // the picker can live inside a system dialog
  167. #define        CanDoApplDialog            64        // the picker can live inside an application
  168. #define        HasOwnDialog            128        // the picker has its own dialog
  169. #define        CanDetach                256        // the picker can detach from a system dialog
  170.  
  171.  
  172. /*
  173. *    The extended picker data structure list-view information the component manager doesn't keep.
  174. *    around. This data is accessed via the kGetIconData message.
  175. */
  176.  
  177. typedef struct PickerIconData
  178. {
  179.     short scriptCode;
  180.     short iconSuiteID;
  181.     ResType helpResType;
  182.     short helpResID;
  183. } PickerIconData;
  184.  
  185. typedef struct PickerInitData
  186. {
  187.     DialogPtr pickerDialog;
  188.     DialogPtr choicesDialog;
  189.     long flags;
  190.     picker yourself;
  191. } PickerInitData;
  192.  
  193. /*
  194. *    Picker error messages
  195. */
  196.  
  197. enum
  198. {
  199.     firstPickerError = -4000,
  200.     
  201.     invalidPickerType = firstPickerError,
  202.     requiredFlagsDontMatch = -4001,
  203.     pickerResourceError = -4002,
  204.     cantLoadPicker = -4003,
  205.     cantCreatePickerWindow = -4004,
  206.     cantLoadPackage = -4005,
  207.     pickerCantLive = -4006,
  208.     colorSyncNotInstalled = -4007,
  209.     badProfileError = -4008,
  210.     noHelpForItem = -4009
  211. };
  212.     
  213. /*
  214. *    The application filter proc for DoPickerEvent
  215. */
  216.  
  217. typedef pascal Boolean (*UserEventProc)(EventRecord *event);
  218.  
  219. /*
  220. *    The application proc to be called when the color changes (called by the picker itself).
  221. */
  222.  
  223. typedef pascal void (*ColorChangedProc)(long userData,PMColorPtr newColor);
  224.  
  225. enum EventForcasters
  226. {
  227.     kNoForcast,            // no forcast (eg an update event)
  228.     kMenuChoice,        // this event will cause a menu to be chosen
  229.     kDialogAccept,        // the dialog will be accepted
  230.     kDialogCancel,        // the dialog will be cancelled
  231.     kLeaveFocus,        // the focus will leave the picker
  232.     kPickerSwitch,        // new picker chosen in more choices list
  233.     kNormalKeyDown,        // a normal key down to an edit field
  234.     kNormalMouseDown    // a normal click within the picker's focus
  235. };
  236.  
  237. typedef short EventForcaster;
  238.  
  239. // the structure that details the location of the edit menu and its items
  240. typedef struct MenuItemInfo
  241. {
  242.     short editMenuID;
  243.     short cutItem;
  244.     short copyItem;
  245.     short pasteItem;
  246.     short clearItem;
  247.     short undoItem;
  248. } MenuItemInfo;
  249.  
  250. // a structure which details the state the picker wishes the edit menu items to be in
  251. typedef struct MenuState
  252. {
  253.     Boolean cutEnabled;
  254.     Boolean copyEnabled;
  255.     Boolean pasteEnabled;
  256.     Boolean clearEnabled;
  257.     Boolean undoEnabled;
  258.     Str255 undoString;
  259. } MenuState;
  260.  
  261. typedef struct ColorPickerInfo
  262. {
  263.     PMColor theColor;
  264.     CMProfileHandle dstProfile;
  265.     long flags;
  266.     DialogPlacementSpec placeWhere;
  267.     Point dialogOrigin;
  268.     long pickerType;
  269.     UserEventProc eventProc;
  270.     ColorChangedProc colorProc;
  271.     long colorProcData;
  272.     Str255 prompt;
  273.     MenuItemInfo mInfo;
  274.     Boolean newColorChosen;
  275. } ColorPickerInfo;
  276.  
  277. typedef struct SystemDialogInfo
  278. {
  279.     long flags;
  280.     long pickerType;
  281.     DialogPlacementSpec placeWhere;
  282.     Point dialogOrigin;
  283.     MenuItemInfo mInfo;
  284. } SystemDialogInfo;
  285.  
  286. typedef struct PickerDialogInfo
  287. {
  288.     long flags;
  289.     long pickerType;
  290.     Point *dialogOrigin;
  291.     MenuItemInfo mInfo;
  292. } PickerDialogInfo;
  293.  
  294. typedef struct ApplicationDialogInfo
  295. {
  296.     long flags;
  297.     long pickerType;
  298.     DialogPtr theDialog;
  299.     Point pickerOrigin;
  300.     MenuItemInfo mInfo;
  301. } ApplicationDialogInfo;
  302.  
  303. typedef struct EventData
  304. {
  305.     EventRecord *event;
  306.     PickerAction action;
  307.     short itemHit;
  308.     Boolean handled;
  309.     ColorChangedProc colorProc;
  310.     long colorProcData;
  311.     EventForcaster forcast;
  312. } EventData;
  313.  
  314. typedef struct EditData
  315. {
  316.     EditOperation theEdit;
  317.     PickerAction action;
  318.     Boolean handled;
  319. } EditData;
  320.  
  321. typedef struct ItemHitData
  322. {
  323.     short itemHit;
  324.     ItemModifier iMod;
  325.     PickerAction action;
  326.     ColorChangedProc colorProc;
  327.     long colorProcData;
  328.     Point where;
  329. } ItemHitData;
  330.     
  331.  
  332. typedef struct HelpItemInfo
  333. {
  334.     long options;
  335.     Point tip;
  336.     Rect altRect;
  337.     short theProc;
  338.     short variant;
  339.     HMMessageRecord helpMessage;
  340. } HelpItemInfo;
  341.  
  342.     /*    High-level routines */
  343. #ifndef __PICKER__
  344. pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor);
  345. #endif
  346. pascal OSErr PickColor(ColorPickerInfo *theColorInfo);
  347.  
  348.     /* Low-level routines */
  349. pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker);
  350. pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker);
  351. pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker);
  352. pascal OSErr DisposeColorPicker(picker thePicker);
  353. pascal OSErr SetPickerVisibility(picker thePicker,short visible);
  354. pascal OSErr GetPickerVisibility(picker thePicker,Boolean *vis);
  355. pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString);
  356. pascal OSErr DoPickerEvent(picker thePicker,EventData *data);
  357. pascal OSErr DoPickerEdit(picker thePicker,EditData *data);
  358. pascal OSErr DoPickerDraw(picker thePicker);
  359. pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
  360. pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color);
  361. pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile);
  362. pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile);
  363. pascal OSErr GetPickerOrigin(picker thePicker,Point *where);
  364. pascal OSErr SetPickerOrigin(picker thePicker,Point where);
  365. pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState);
  366. pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo);
  367.  
  368.  
  369. /* stuff from the old Picker.h */
  370.  
  371.  
  372. enum {MaxSmallFract = 0x0000FFFF};  /*Maximum small fract value, as long*/
  373.  
  374.  
  375. /* A SmallFract value is just the fractional part of a Fixed number,
  376. which is the low order word.  SmallFracts are used to save room,
  377. and to be compatible with Quickdraw's RGBColor.  They can be
  378. assigned directly to and from INTEGERs. */
  379.  
  380. typedef unsigned short SmallFract;    /* Unsigned fraction between 0 and 1 */
  381.  
  382. /* For developmental simplicity in switching between the HLS and HSV
  383. models, HLS is reordered into HSL.    Thus both models start with
  384. hue and saturation values; value/lightness/brightness is last. */
  385.  
  386.  
  387.  
  388. struct HSVColor {
  389.     SmallFract hue;                 /*Fraction of circle, red at 0*/
  390.     SmallFract saturation;            /*0-1, 0 for gray, 1 for pure color*/
  391.     SmallFract value;                /*0-1, 0 for black, 1 for max intensity*/
  392. };
  393.  
  394. typedef struct HSVColor HSVColor;
  395. /* For developmental simplicity in switching between the HLS and HSVmodels, HLS
  396.  is reordered into HSL.  Thus both models start with hue and saturation values;
  397.  value/lightness/brightness is last. */
  398. struct HSLColor {
  399.     SmallFract hue;                 /*Fraction of circle, red at 0*/
  400.     SmallFract saturation;            /*0-1, 0 for gray, 1 for pure color*/
  401.     SmallFract lightness;            /*0-1, 0 for black, 1 for white*/
  402. };
  403.  
  404. typedef struct HSLColor HSLColor;
  405. struct CMYColor {
  406.     SmallFract cyan;
  407.     SmallFract magenta;
  408.     SmallFract yellow;
  409. };
  410.  
  411. typedef struct CMYColor CMYColor;
  412. #ifdef __cplusplus
  413. extern "C" {
  414. #endif
  415. pascal SmallFract Fix2SmallFract(Fixed f)
  416.     = {0x3F3C,0x0001,0xA82E};
  417. pascal Fixed SmallFract2Fix(SmallFract s)
  418.     = {0x3F3C,0x0002,0xA82E};
  419. pascal void CMY2RGB(const CMYColor *cColor,RGBColor *rColor)
  420.     = {0x3F3C,0x0003,0xA82E};
  421. pascal void RGB2CMY(const RGBColor *rColor,CMYColor *cColor)
  422.     = {0x3F3C,0x0004,0xA82E};
  423. pascal void HSL2RGB(const HSLColor *hColor,RGBColor *rColor)
  424.     = {0x3F3C,0x0005,0xA82E};
  425. pascal void RGB2HSL(const RGBColor *rColor,HSLColor *hColor)
  426.     = {0x3F3C,0x0006,0xA82E};
  427. pascal void HSV2RGB(const HSVColor *hColor,RGBColor *rColor)
  428.     = {0x3F3C,0x0007,0xA82E};
  429. pascal void RGB2HSV(const RGBColor *rColor,HSVColor *hColor)
  430.     = {0x3F3C,0x0008,0xA82E};
  431.  
  432. #ifndef RUN_LINKED_IN
  433. #ifndef __PICKER__
  434. pascal Boolean GetColor(Point where,Str255 prompt,RGBColor *inColor,RGBColor *outColor)
  435.     = {0x3F3C,0x0009,0xA82E};
  436. #endif
  437. pascal OSErr PickColor(ColorPickerInfo *theColorInfo)
  438.     = {0x3F3C,0x0213,0xA82E};
  439. pascal OSErr AddPickerToDialog(ApplicationDialogInfo *info,picker *thePicker)
  440.     = {0x3F3C,0x0414,0xA82E};
  441. pascal OSErr CreateColorDialog(SystemDialogInfo *info,picker *thePicker)
  442.     = {0x3F3C,0x0415,0xA82E};
  443. pascal OSErr CreatePickerDialog(PickerDialogInfo *info,picker *thePicker)
  444.     = {0x3F3C,0x0416,0xA82E};
  445. pascal OSErr DisposeColorPicker(picker thePicker)
  446.     = {0x3F3C,0x0217,0xA82E};
  447. pascal OSErr GetPickerVisibility(picker thePicker,Boolean *visible)
  448.     = {0x3F3C,0x0418,0xA82E};
  449. pascal OSErr SetPickerVisibility(picker thePicker,short visible)
  450.     = {0x3F3C,0x0319,0xA82E};
  451. pascal OSErr SetPickerPrompt(picker thePicker, Str255 promptString)
  452.     = {0x3F3C,0x041a,0xA82E};
  453. pascal OSErr DoPickerEvent(picker thePicker,EventData *data)
  454.     = {0x3F3C,0x041b,0xA82E};
  455. pascal OSErr DoPickerEdit(picker thePicker,EditData *data)
  456.     = {0x3F3C,0x041c,0xA82E};
  457. pascal OSErr DoPickerDraw(picker thePicker)
  458.     = {0x3F3C,0x021d,0xA82E};
  459. pascal OSErr GetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
  460.     = {0x3F3C,0x051e,0xA82E};
  461. pascal OSErr SetPickerColor(picker thePicker,ColorType whichColor,PMColorPtr color)
  462.     = {0x3F3C,0x051f,0xA82E};
  463. pascal OSErr GetPickerOrigin(picker thePicker,Point *where)
  464.     = {0x3F3C,0x0420,0xA82E};
  465. pascal OSErr SetPickerOrigin(picker thePicker,Point where)
  466.     = {0x3F3C,0x0421,0xA82E};
  467. pascal OSErr GetPickerProfile(picker thePicker,CMProfileHandle *profile)
  468.     = {0x3F3C,0x0422,0xA82E};
  469. pascal OSErr SetPickerProfile(picker thePicker,CMProfileHandle profile)
  470.     = {0x3F3C,0x0423,0xA82E};
  471. pascal OSErr GetPickerEditMenuState(picker thePicker,MenuState *mState)
  472.     = {0x3F3C,0x0424,0xA82E};
  473. pascal OSErr ExtractPickerHelpItem(picker thePicker,short itemNo,short whichState,HelpItemInfo *helpInfo)
  474.     = {0x3F3C,0x0625,0xA82E};
  475.  
  476. #endif
  477. #ifdef __cplusplus
  478. }
  479. #endif
  480.  
  481. #endif